<?php
namespace app\common\order\model;

use app\common\config\logic\CommonPickerLogic;
use app\common\system\logic\UserLogic;
use think\Model;
use think\model\concern\SoftDelete;

class OrderIncome extends Model
{
    use SoftDelete;
    protected $defaultSoftDelete = 0;

    protected $type = [
        'receipt' => 'json',
        'note' => 'json',
        'income_date' => 'timestamp',
        'check_time' => 'timestamp',
    ];

    public function order()
    {
        return $this->hasOne(Order::class, 'id', 'order_id');
    }

    public function getWayAttr($value, $data) {
        $commonLogic = new CommonPickerLogic();
        return $commonLogic->getPickerItem('paidWay', $data['income_way_id']);
    }

    public function getTypeAttr($value, $data) {
        $commonLogic = new CommonPickerLogic();
        return $commonLogic->getPickerItem('paidType', $data['income_type_id']);
    }

    public function getUserAttr($value, $data) {
        $userLogic = new UserLogic();
        return $userLogic->getUser($data['user_id'], ['id', 'realname', 'status']);
    }

    public function getCheckTagAttr($value, $data) {
        $index = $data['check_status'];
        $map = [
            -1 => '暂存',
            0 => '待审核',
            1 => '审核中',
            2 => '审核通过',
            3 => '审核驳回'
        ];

        return $map[$index];
    }
}